package com.workflow.engine.eb.steps.jd.data;

import com.workflow.engine.core.flow.StepState;
import com.workflow.engine.parser.annotation.PGConfig;
import com.workflow.engine.parser.annotation.PGScheme;
import com.workflow.engine.parser.constant.HttpMethod;
import com.workflow.engine.parser.flow.impl.AbstractStep;
import com.workflow.engine.parser.strategy.StrategyType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

import static com.workflow.engine.parser.constant.HttpMethod.GET;
import static com.workflow.engine.parser.utils.StepStateUtil.successfulStepState;

/**
 * Created by Administrator on 2017/6/11.
 */
@PGConfig({
        @PGScheme(requestParamName = "callback", strategy = StrategyType.FIXED, strategyNeedParams = "callback"),
        @PGScheme(requestParamName = "_", strategy = StrategyType.FIXED, strategyNeedParams = "1497165957657"),
})
public class JDGetCouponCount extends AbstractStep {
    private static final Logger logger = LoggerFactory.getLogger(JDGetCouponCount.class);

    @Override
    public Logger getLogger() {
        return logger;
    }

    @Override
    protected String getRequestUrl() {
        return "https://quan.jd.com/getcouponcount.action";
    }

    @Override
    protected HttpMethod getHttpMethod() {
        return GET;
    }

    @Override
    protected Map<String, String> getHeaders() {
        return new HashMap<String, String>(){{
            put("Host", "quan.jd.com");
            put("Connection", "keep-alive");
            put("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");
            put("Accept", "*/*");
            put("Referer", "https://home.jd.com/");
            put("Accept-Encoding", "gzip, deflate, sdch, br");
            put("Accept-Language", "zh-CN,zh;q=0.8");
        }};
    }

    @Override
    protected StepState handleResponse(Map<String, Object> context, Object response) throws Exception {
        logger.info("result is {}", response);
        return successfulStepState(this);
    }
}
